﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Utilities;

namespace ManageTicket.Human
{
    public partial class frmSearchEmployee : Form
    {
        #region Contructor
        public frmSearchEmployee()
        {
            InitializeComponent();
        }
        #endregion

        #region Variable
        clsMethod4All objMethod = new clsMethod4All();
        ManageTicket.Library.Common.CommonFunction clsCommonFunc = new ManageTicket.Library.Common.CommonFunction();
        public ArrayList arrResult;
        #endregion

        #region Event
        private void frmSearchEmployee_Load(object sender, EventArgs e)
        {
            arrResult = new ArrayList();

            DataObjects.CodeType oCodeType = new DataObjects.CodeType();
            oCodeType.CodeTypeId = "";
            oCodeType.CodeTypeName = "";
            clsCommonFunc.GetListCodeType(cboGender, "GENDER", oCodeType);
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            Business.Employee   boEmployee  = new Business.Employee();
            Business.CodeType   boCodeType  = new Business.CodeType();
            Business.Department boDept      = new Business.Department();
            
            DataObjects.CodeType    oCodeType;
            DataObjects.Department  oDept;

            object[] oParam = new object[4];
            oParam[0] = txtEmployeeId.Text;                                     //Employee_Id
            oParam[1] = txtFullName.Text;                                       //Full_Name
            oCodeType = (DataObjects.CodeType)(cboGender.SelectedItem);
            oParam[2] = oCodeType != null ? oCodeType.CodeTypeId : "";          //Gender
            oParam[3] = "CUR";                                                  //Status

            //goi ham search
            ArrayList arr = new ArrayList();
            arr = boEmployee.SearchEmployee(oParam);

            //danh sach tra ve
            lvwEmployee.Items.Clear();
            ListViewItem item;
            oCodeType = null;
            foreach (DataObjects.Employee oEmp in arr)
            {
                item = new ListViewItem();
                item.Text = oEmp.EmployeeId;
                item.SubItems.Add(oEmp.LastName);
                item.SubItems.Add(oEmp.FirstName);
                oCodeType = boCodeType.GetObjectByPK(oEmp.Gender);
                if (oCodeType != null)
                    item.SubItems.Add(oCodeType.CodeTypeName);
                else
                    item.SubItems.Add("");
                oDept = boDept.GetObjectByPK(oEmp.DepartmentId);
                if (oDept != null)
                    item.SubItems.Add(oDept.DepartmentName);
                else
                    item.SubItems.Add("");

                lvwEmployee.Items.Add(item);
            }
            lblCount.Text = "Tổng: " + lvwEmployee.Items.Count.ToString();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            arrResult = new ArrayList();
            DataObjects.Employee oEmp;
            foreach (ListViewItem item in lvwEmployee.CheckedItems)
            {
                oEmp = new DataObjects.Employee();
                oEmp.EmployeeId = item.Text;
                oEmp.LastName = item.SubItems[1].Text;
                oEmp.FirstName = item.SubItems[2].Text;

                arrResult.Add(oEmp);
            }
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            arrResult = new ArrayList();
            this.Close();
        }

        private void chkAll_CheckedChanged(object sender, EventArgs e)
        {
            foreach (ListViewItem item in lvwEmployee.Items)
            {
                item.Checked = chkAll.Checked;
            }
        }
        #endregion

        #region Execute
        #endregion

        #region Method
        #endregion

        

        
    }
}
